using System;
using System.Collections.Generic;
using System.Text;
using FlatRedBall;
using FlatRedBall.Input;
using FlatRedBall.AI.Pathfinding;
using FlatRedBall.Graphics.Animation;
using FlatRedBall.Graphics.Particle;

using FlatRedBall.Math.Geometry;
using FlatRedBall.Math.Splines;
using BitmapFont = FlatRedBall.Graphics.BitmapFont;
using Cursor = FlatRedBall.Gui.Cursor;
using GuiManager = FlatRedBall.Gui.GuiManager;

#if FRB_XNA || SILVERLIGHT
using Keys = Microsoft.Xna.Framework.Input.Keys;
using Vector3 = Microsoft.Xna.Framework.Vector3;
using Texture2D = Microsoft.Xna.Framework.Graphics.Texture2D;


#endif

using NereusGame.Entities.Ships;
namespace NereusGame.Entities.Projectiles
{
	public partial class Projectile
	{
        protected enum ProjectileState
        {
            Alive,
            Dead
        }

        protected ProjectileState state;            // tracks state of the projectile
        protected int lifeCycle;                    // for ow many the projectile can stay alive
        protected int initialLifeCycle;
        public float DefaultVelocity;
        public float Damage;
        public Ship Shooter;

		private void CustomInitialize()
		{
            lifeCycle = initialLifeCycle = 300;
            DefaultVelocity = 1;
            Damage = 0;

		}

		private void CustomActivity()
		{
            CheckRange();

		}

		private void CustomDestroy()
		{
            base.Destroy();

		}

        private static void CustomLoadStaticContent(string contentManagerName)
        {


        }

        public virtual void Shoot(Ship s, Vector3 direction, float rotation, Vector3 velocity)
        {
            Shooter = s;
            AliveState();
            RotationZ = rotation;
            Velocity = direction;
            Velocity *= DefaultVelocity;
            Velocity += velocity;
        }


        // returns true if the projectile is alive
        public bool IsAlive()
        {
            if (state == ProjectileState.Alive)
                return true;
            return false;
        }

        // if projectile is alive it will decrement the lifeCycle count.
        private void CheckRange()
        {
            if (state == ProjectileState.Alive)
            {
                lifeCycle--;
                // reset lfecycle
                if (lifeCycle <= 0)
                    DeadState();
                    
            }
        }

        // kill the projectile
        public void DeadState()
        {
            Body.Visible = false;
            Tex.Visible = false;
            state = ProjectileState.Dead;
        }

        // resurrect the projectile
        public void AliveState()
        {
            Tex.Visible = true;
            state = ProjectileState.Alive;
            lifeCycle = initialLifeCycle;

        }
	}
}
